{template header}
<style type="text/css">
  .focusDiv {border-bottom: 2px solid #EEEEEE;}
  ul.link{margin: 10px auto;}
  ul.link li{list-style-type: none; float: left; margin: 2px 0px;  margin-right: 15px;  background-color:#dbeaf9;padding:5px 10px; cursor: pointer;border-radius: 4px;}
</style>
<script type="text/javascript">
  $(document).ready(function(){
      $("#link>li").click(function()
      {
         url = $(this).attr("data-url");
         $(this).parent().siblings("input").val(url);
         alert('友情提示，不要忘记替换大括号中参数，并删除大括号');
      });
      $("button#addFocusImg").click(function(){
            var num = $("#totalFocusImg").val();
            if($("#focusImgList").children().length >= 8)
            {
                alert('焦点图不宜过多');
                return false;
            }
            num = parseInt(num) +1;
            $("#totalFocusImg").val(num);
            var newHtml = "<div class='control-group focusDiv' id='focusImg_"+num+"'><label class='control-label' for='inputTiltle'>焦点图（"+num+"）：</label><div class='controls'><div class='control-group'><div><span>图片：</span><input type='file' name='picture_"+num+"'></div></div></div><div class='control-group'><div class='controls'><span>跳转链接：</span><input type='text' name='link["+num+"]' placeholder='不需要跳转时请留空'>&nbsp; <span class=\"label\">排序</span> <input type=\"text\" name=\"sort["+num+"]\" style=\"font-size:12px;\" class=\"input-mini\" placeholder=\"数字大在前\"><ul id='link' class='link'>{loop $urlArr $kk $v}<li data-url='{$v['link']}' onclick='showLinkUrl(this)'>{$v['name']}</li>{/loop}</ul></div></div><div class='controls'><button type='button' class='btn btn-danger' onclick='delFocusImg("+num+")'>删除本焦点图</button></div></div>";
            $("#focusImgList").append(newHtml);
      });
    });
   function showLinkUrl(frm){
        url = $(frm).attr("data-url");
         $(frm).parent().siblings("input").val(url);
         alert('友情提示，不要忘记替换大括号中参数，并删除大括号');
   }
  function delFocusImg(key)
  {
    if(confirm("确认删除？") == true)
    {
        $("#focusImg_"+key).remove();
        var num = $("#totalFocusImg").val();
        num = parseInt(num);
        for(var i=num; i>=0; i--){
            if($("#focusImg_"+i).html() !== undefined){
                $("#totalFocusImg").val(i);
                return false;
            }
        }
    }
  }
</script>
<form class="form-horizontal" action="index.php?c=admin&a=editFocusImg" method="post" enctype="multipart/form-data">
<div id="focusImgList">
{loop $focusImg $k $img}
  <div class="control-group focusDiv ptb-20" id="focusImg_{$k}">
    <label class="control-label" for="inputTiltle">焦点图 ({$k}):<br>750*315 50K以内</label>
    <div class="controls">
      <div class="control-group">
        <div class="">
          <span>图片：</span>
          {if $img['pictureUrl']}
            <img width="50" src="{$img['pictureUrl']}" alt="焦点图">
          {/if}
          <input type="file" name="picture_{$k}">
        </div>
      </div>
    </div>
    <div class="control-group">
        <div class="controls">
            <span>跳转链接：</span>
            <input type="text" name="link[{$k}]" placeholder="不需要跳转时请留空" value="{$img['linkUrl']}">
            &nbsp; <span class="label">排序</span>
            <input type="text" name="sort[{$k}]" style="font-size:12px;" class="input-mini" placeholder="数字大在前" value="{$img['sort']}">
            <ul id="link" class="link">
                {loop $urlArr $kk $v}
                <li data-url="{$v['link']}">{$v['name']}</li>
                {/loop}
            </ul>
        </div>
      </div>
      <div class="controls"><button type="button" class="btn btn-danger" onclick="delFocusImg('{$k}')">删除本焦点图</button></div>
  </div>
{/loop}
</div>
<div class="control-group">
    <div class="controls">
        <input type="hidden" value="{$k}" id="totalFocusImg" name="num">`
        <button type="button" class="btn btn-primary" id="addFocusImg">添加一个焦点图</button>
    </div>
</div>
<div class="control-group">
    <div class="controls">
        <button type="submit" class="btn">提交</button>
    </div>
</div>
</form>
{template footer}
